<?
/*
 * Copyright 2004-2005 Sigve Indregard.
 *
 * This file is part of Laivsys.
 *
 * Laivsys is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Laivsys is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Laivsys; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * $Id: rollebeskrivelse.php 6 2005-07-11 23:14:47Z say $
 */
 
include("../db.php");
include("auth.php");
include("top.php");
include("rollerinclude.php");
rollermeny();
echo "<h1>Rollebeskrivelse</h1>";

$rid = $_REQUEST['rid'];
if ($rid=="" || is_null(getRolle($rid)) )
	echo("Ulovlig id");	
else {
	if ($_REQUEST['process'] == 'true') {
		$str=$_REQUEST['beskrivelse'];
		$sql="UPDATE r_Rolle SET beskrivelse='$str' WHERE ID='{$_REQUEST['rid']}'";
		mysql_query($sql);
		if (mysql_errno())
			echo "En feil oppstod: ".mysql_error();
		else {
			echo "Beskrivelsen ble oppdatert";
			logit("Endret rollebeskrivelsen");
		}
	}
	$rolle=getRolle($rid);
	echo "<p><a href=\"rolledetaljer.php?id={$_REQUEST['rid']}\">Tilbake til rolledetaljene</a></p>";
	echo "<h2>Forh�ndsvisning</h2>\n";

	echo "<div style=\"background:white;border:1px solid black;padding:5px\">";
	$beskrivelse = completeRollebeskrivelse($rolle['ID'], "rollebeskrivelse.php?rid=");
	echo "</div>";
	echo "\n\n<h2>Rediger</h2>";
	?>
	<a href="#koder">Rollekoder</a> i hakeparenteser ({}) vil bli erstattet
	av karakterens virkelige navn eller rollenavn i utskriften til deltakeren. Dersom du setter en 
	$ foran koden, vil det gj�res om til bare fornavn.
	<p>	
	<form method="post" action="rollebeskrivelse.php">
	<input type="hidden" name="rid" value="<?=$rid?>">
	<input type="hidden" name="process" value="true">
	<textarea name="beskrivelse" cols="60" rows="50"><?=htmlspecialchars($rolle['beskrivelse'])?></textarea>
	<p>
	<input type="submit" value="Lagre">
	<input type="reset" value="Tilbakestill">
	</form>
	<p>
	<a name="koder"></a>
	<h2>Gyldige rollekoder</h2>
	<table>
	<?	
	$sql="SELECT rollekode, rollenavn, familienavn, tentativcasting FROM r_Rolle WHERE LaivID=$laivid ORDER BY rollekode";
	$koder=mysql_query($sql);
	while ($kode=mysql_fetch_row($koder)) {
		echo "<tr><th>{$kode[0]}</th>";
		echo "<td>{$kode[1]} {$kode[2]}</td>";
		echo "<td>{$kode[3]}</td>";
		echo "</tr>\n";
	}
	?>
	</ul>
	<?
}
include("bottom.php");
?>
